﻿<%@ WebHandler Language="C#" Class="Training.Web.AjaxHandler.Loaddata.Administration.Catalog.PesertaLoadHandler" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Text;

using Training.Library.DataAccess.Administration;
using Training.Library.DomainObject.Administration;
using Training.Library.DataAccess.Administration.Catalog;
using Training.Library.DomainObject.Administration.Catalog;

using Training.Library.Enum;
using Training.Web.Support;
using SIPO.Library.DataAccess.Administration.Catalog;
using SIPO.Library.DomainObject.Administration.Catalog;

using Newtonsoft.Json.Linq;

namespace Training.Web.AjaxHandler.Loaddata.Administration.Catalog
{

    public class PesertaLoadHandler : Training.Web.BaseHandler
    {

        PesertaRepo PesertaDal = new PesertaRepo(ConfigurationManager.ConnectionStrings["TrainingConn"].ConnectionString);
        string MethodName = string.Empty;

        public override void ProcessRequest(HttpContext context)
        {
            base.ProcessRequest(context);

            StringBuilder sbProject = new StringBuilder();
            if (context.Request.Params["method"] != null)
                MethodName = context.Request.Params["method"];

            if (MethodName == "getbyid")
            {
                int pesertaID = Convert.ToInt32(context.Request.Params["pesertaID"].ToString());
                //List<Peserta> list = PesertaDal.GetList();
                //var result = list.Where(x => x.PesertaID == pesertaID); ;
                //context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));
                
                Peserta objPeserta = PesertaDal.GetById(pesertaID);

                PositionRepo PositionDal = new PositionRepo(ConfigurationManager.ConnectionStrings["JobdescConn"].ConnectionString);
                Position objPosition = PositionDal.GetById(Convert.ToInt32(objPeserta.PositionID));

                DepartmentRepo DepartmentDal = new DepartmentRepo(ConfigurationManager.ConnectionStrings["JobdescConn"].ConnectionString);
                Department objDept = DepartmentDal.GetById(Convert.ToInt32(objPosition.DepartmentID));

                BagianRepo BagianDal = new BagianRepo(ConfigurationManager.ConnectionStrings["TrainingConn"].ConnectionString);
                Bagian objBagian = BagianDal.GetById(Convert.ToInt32(objPeserta.BagianID));


                sbProject.Append("{");
                sbProject.AppendFormat("  {0}NamaPeserta{0}:{0}{1}{0}", "\"", objPeserta.NamaPeserta);
                sbProject.Append(",");
                sbProject.AppendFormat("  {0}Jabatan{0}:{0}{1}{0}", "\"", objPosition.PositionName);
                //sbProject.Append("}");
                sbProject.Append(",");
                sbProject.AppendFormat("  {0}Bagian{0}:{0}{1}{0}", "\"", objBagian.NamaBagian);
                //sbProject.Append("}");
                sbProject.Append(",");
                sbProject.AppendFormat("  {0}Departemen{0}:{0}{1}{0}", "\"", objDept.DepartmentDesc);
                sbProject.Append("}");
                context.Response.Write(sbProject.ToString());
                

            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}